# -*- mode: python; coding: utf-8; -*-
##--------------------------------------------------------------------------##
##
## Copyright (C) 1998-2003 Markus Oberhumer <markus@oberhumer.com>
## Copyright (C) 2003 Mt. Hood Playing Card Co.
## Copyright (C) 2005-2010 Skomoroh <skomoroh@users.sourceforge.net>
## Copyright (C) 2010-2013 Jeremy Austin-Bardo <tjaustinbardo@gmail.com>
##
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program.  If not, see <http://www.gnu.org/licenses/>.
##
##--------------------------------------------------------------------------##
__docformat__ = 'restructuredtext en'
__all__ = []

from ... import pilelib as stack
from ...forms import hanafuda as hlayout
from ...gamelib import info as gi, game
from ...packlib import info as cs
from ...piles import hanafuda as hstack
from ...utillib.misc import kwdefault
from .. import klondike

GT, SL = gi.GT, gi.SL
Wrap = stack.StackWrapper


class Samuri(cs.Hanafuda_Deck, game.Game):
    """
    Finish 1 deck on _foundation_.

    :CVariables:
      _layout_ : pysollib.layout.Layout
        .. pysollib.layouts.hanafuda.SamuriLayout
        - row [7 horz N, vert offset]
        - talon [1 S, no offset]
        - waste [1 E talon, no offset]
        - foundation [6 vert W 6 vert E, no offset]

      _talon_ : pysollib.stack.Stack
        .. pysollib.stack.WasteTalon (max_rounds=INFINITE, num_deal=3)

        Deal 3 card per `s.waste` on click. Unlimited redeals.

      _waste_ : pysollib.stack.Stack
        .. pysollib.stack.WasteStack

        Init 3 card. Build none. Play top.

      _foundation_ : pysollib.stack.Stack
        .. pysollib.stacks.hanafuda.Rank_Foundation

        Build up in rank by same suit. Play top.

      _row_ : pysollib.stack.Stack
        .. pysollib.stacks.hanafuda.RankSS_RowStack

        Init 3..6..3 card. Build down in rank by same suit. Play any. Base 1st
        rank.

      _hint_ : pysollib.hint.AbstractHint
        .. pysollib.hint.CautiousDefaultHint
    """
    __info__ = dict(id=0x2531e, name='Samuri', category=cs.TYPE_HANAFUDA,
                    game_type=GT.KLONDIKE, decks=1, skill_level=SL.BALANCED,
                    version='3.20')
    __author__ = 'Markus Oberhumer'
    __version__ = 7.70

    _layout_ = hlayout.SamuriLayout
    _talon_ = stack.WasteTalon
    _waste_ = stack.WasteStack
    _foundation_ = hstack.Rank_Foundation
    _row_ = Wrap(hstack.RankSS_RowStack, base_rank=cs.FIRST)

    def _create_game(self, **kw):
        kwdefault(kw, rows=7, texts=True, playcards=21)
        return super(Samuri, self)._create_game(**kw)

    def _start(self):
        for i in range(1 + (self['decks'] > 1)):
            self.s['talon'].dealRow(flip=False, frames=0)
        for i in range(len(self.s['rows'])):
            self.s['talon'].dealRow(rows=self.s['rows'][i:-i], flip=False,
                                    frames=0)
        self._play_sound('deal')
        self.s['talon'].dealRow()
        self.s['talon'].deal_cards()


class DoubleSamuri(Samuri):
    """
    Finish 2 deck on _foundation_.

    :CVariables:
      _layout_ : pysollib.layout.Layout
        .. pysollib.layouts.hanafuda.SamuriLayout
        - row [11 horz N, vert offset]
        - talon [1 S, no offset]
        - waste [1 E talon, no offset]
        - foundation [12 over 2 col vert W 12 over 2 col vert E, no
          offset]

      _talon_ : pysollib.stack.Stack
        .. pysollib.stack.WasteTalon (max_rounds=INFINITE, num_deal=3)

        Deal 3 card per `s.waste` on click. Unlimited redeals.

      _waste_ : pysollib.stack.Stack
        .. pysollib.stack.WasteStack

        Init 3 card. Build none. Play top.

      _foundation_ : pysollib.stack.Stack
        .. pysollib.stacks.hanafuda.Rank_Foundation

        Build up in rank by same suit. Play top.

      _row_ : pysollib.stack.Stack
        .. pysollib.stacks.hanafuda.RankSS_RowStack

        Init 4..9..4 card. Build down in rank by same suit. Play any. Base 1st
        rank.

      _hint_ : pysollib.hint.AbstractHint
        .. pysollib.hint.CautiousDefaultHint
    """
    __info__ = dict(id=0x2532a, name='Double Samuri',
                    category=cs.TYPE_HANAFUDA, game_type=GT.KLONDIKE, decks=2,
                    version='0.50fc', skill_level=SL.BALANCED,
                    altnames=('Samuri (2 Decks)',))
    __author__ = 'Mt. Hood Playing Card'
    __version__ = 7.70

    def _create_game(self, **kw):
        kw.setdefault('rows', 11)
        return super(DoubleSamuri, self)._create_game(**kw)


class SuperSamuri(DoubleSamuri):
    """
    Finish 3 deck on _foundation_.

    :CVariables:
      _layout_ : pysollib.layout.Layout
        .. pysollib.layouts.hanafuda.SamuriLayout
        - row [11 horz N, vert offset]
        - talon [1 S, no offset]
        - waste [1 E talon, no offset]
        - foundation [24 over 4 col vert W 24 over 4 col vert E, no
          offset]

      _talon_ : pysollib.stack.Stack
        .. pysollib.stack.WasteTalon (max_rounds=INFINITE, num_deal=3)

        Deal 3 card per `s.waste` on click. Unlimited redeals.

      _waste_ : pysollib.stack.Stack
        .. pysollib.stack.WasteStack

        Init 3 card. Build none. Play top.

      _foundation_ : pysollib.stack.Stack
        .. pysollib.stacks.hanafuda.Rank_Foundation

        Build up in rank by same suit. Play top.

      _row_ : pysollib.stack.Stack
        .. pysollib.stacks.hanafuda.Rank_RowStack

        Init 4..9..4 card. Build down in rank by same suit. Play any. Base 1st
        rank.

      _hint_ : pysollib.hint.AbstractHint
        .. pysollib.hint.CautiousDefaultHint
    """
    __info__ = dict(id=0x2532b, name='Super Samuri',
                    category=cs.TYPE_HANAFUDA, game_type=GT.KLONDIKE, decks=4,
                    version='0.50fc', skill_level=SL.BALANCED,
                    altnames=('Samuri (4 Decks)',))
    __author__ = 'Mt. Hood Playing Card'
    __version__ = 7.70


class Paulownia(cs.Hanafuda_Deck, klondike.Klondike):
    """
    Finish 1 deck on _foundation_.

    :CVariables:
      _layout_ : pysollib.layout.Layout
        .. pysollib.layouts.klondike.KlondikeLayout

        - row [8 horz S foundation, vert offset]
        - talon [1 NW, no offset]
        - waste [1 E talon, no offset]
        - foundation [8 over 2 rows N, no offset]

      _talon_ : pysollib.stack.Stack
        .. pysollib.stack.WasteTalon (max_rounds=INFINITE)

        Deal 1 card per `s.waste` on click. Unlimited redeals.

      _waste_ : pysollib.stack.Stack
        .. pysollib.stack.WasteStack

        Init 1 card. Build none. Play top.

      _foundation_ : pysollib.stack.Stack
        .. pysollib.stacks.hanafuda.Rank_Foundation

        Build up in rank by same suit. Play top.

      _row_ : pysollib.stack.Stack
        .. pysollib.stacks.hanafuda.RankSS_RowStack (base_rank=cs.FIRST)

        Init 1..8 card. Build down in rank by same suit. Play any. Base 1st
        rank.

      _hint_ : pysollib.hint.AbstractHint
        .. pysollib.hint.CautiousDefaultHint
    """
    __info__ = dict(id=0x25331, name='Paulownia', category=cs.TYPE_HANAFUDA,
                     game_type=GT.KLONDIKE, decks=1, redeals=cs.INFINITE,
                     skill_level=SL.BALANCED, version='0.50fc')
    __author__ = 'Mt. Hood Playing Card'
    __version__ = 7.70

    _foundation_ = hstack.Rank_Foundation
    _row_ = Wrap(hstack.RankSS_RowStack, base_rank=cs.FIRST)

    def _create_game(self, **kw):
        kw.setdefault('rows', 8)
        return super(Paulownia, self)._create_game(**kw)


class Pine(Paulownia):
    """
    Finish 1 deck on _foundation_.

    :CVariables:
      _layout_ : pysollib.layout.Layout
        .. pysollib.layouts.klondike.KlondikeLayout

        - row [8 horz S foundation, vert offset]
        - talon [1 NW, no offset]
        - waste [1 E talon, no offset]
        - foundation [8 over 2 rows N, no offset]

      _talon_ : pysollib.stack.Stack
        .. pysollib.stack.WasteTalon

        Deal 3 card per `s.waste` on click. no redeals.

      _waste_ : pysollib.stack.Stack
        .. pysollib.stack.WasteStack

        Init 3 card. Build none. Play top.

      _foundation_ : pysollib.stack.Stack
        .. pysollib.stacks.hanafuda.Rank_Foundation

        Build up in rank by same suit. Play top.

      _row_ : pysollib.stack.Stack
        .. pysollib.stacks.hanafuda.RankSS_RowStack (base_rank=cs.FIRST)

        Init 1..8 card. Build down in rank by same suit. Play any. Base 1st
        rank.

      _hint_ : pysollib.hint.AbstractHint
        .. pysollib.hint.CautiousDefaultHint
    """
    __info__ = dict(id=0x2533f, name='Pine', category=cs.TYPE_HANAFUDA,
                    game_type=GT.KLONDIKE, decks=1, skill_level=SL.BALANCED,
                    version='0.50fc')
    __author__ = 'Mt. Hood Playing Card'
    __version__ = 7.70

    _talon_ = Wrap(stack.WasteTalon, num_deal=3)


class Eularia(Paulownia):
    """
    Finish 1 deck on _foundation_.

    :CVariables:
      _layout_ : pysollib.layout.Layout
        .. pysollib.layouts.klondike.KlondikeLayout

        - row [8 horz S foundation, vert offset]
        - talon [1 NW, no offset]
        - waste [1 E talon, no offset]
        - foundation [8 over 2 rows N, no offset]

      _talon_ : pysollib.stack.Stack
        .. pysollib.stack.WasteTalon (max_rounds=INFINITE)

        Deal 1 card per `s.waste` on click. Unlimited redeals.

      _waste_ : pysollib.stack.Stack
        .. pysollib.stack.WasteStack

        Init 1 card. Build none. Play top.

      _foundation_ : pysollib.stack.Stack
        .. pysollib.stacks.hanafuda.Rank_Foundation

        Build up in rank by same suit. Play top.

      _row_ : pysollib.stack.Stack
        .. pysollib.stacks.hanafuda.RankSS_RowStack

        Init 1..8 card. Build down in rank alone. Play any.

      _hint_ : pysollib.hint.AbstractHint
        .. pysollib.hint.CautiousDefaultHint
    """
    __info__ = dict(id=0x2533c, name='Eularia', category=cs.TYPE_HANAFUDA,
                    game_type=GT.KLONDIKE, decks=1, redeals=cs.INFINITE,
                    skill_level=SL.BALANCED, version='0.50fc')
    __author__ = 'Mt. Hood Playing Card'
    __version__ = 7.70

    _row_ = hstack.Rank_RowStack


class Peony(Eularia):
    """
    Finish 1 deck on _foundation_.

    :CVariables:
      _layout_ : pysollib.layout.Layout
        .. pysollib.layouts.klondike.KlondikeLayout

        - row [8 horz S foundation, vert offset]
        - talon [1 NW, no offset]
        - waste [1 E talon, no offset]
        - foundation [8 over 2 rows N, no offset]

      _talon_ : pysollib.stack.Stack
        .. pysollib.stack.WasteTalon (max_rounds=INFINITE, num_deal=3)

        Deal 3 card per `s.waste` on click. Unlimited redeals.

      _waste_ : pysollib.stack.Stack
        .. pysollib.stack.WasteStack

        Init 3 card. Build none. Play top.

      _foundation_ : pysollib.stack.Stack
        .. pysollib.stacks.hanafuda.Rank_Foundation

        Build up in rank by same suit. Play top.

      _row_ : pysollib.stack.Stack
        .. pysollib.stacks.hanafuda.Rank_RowStack

        Init 1..8 card. Build down in rank alone. Play any.

      _hint_ : pysollib.hint.AbstractHint
        .. pysollib.hint.CautiousDefaultHint
    """
    __info__ = dict(id=0x2533d, name='Peony', category=cs.TYPE_HANAFUDA,
                    game_type=GT.KLONDIKE, decks=1,
                    redeals=cs.INFINITE, skill_level=SL.BALANCED,
                    version='0.50fc')
    __author__ = 'Mt. Hood Playing Card'
    __version__ = 7.70

    talon_ = Wrap(stack.WasteTalon, max_rounds=cs.INFINITE, num_deal=3)


class Iris(Peony):
    """
    Finish 1 deck on _foundation_.

    :CVariables:
      _layout_ : pysollib.layout.Layout
        .. pysollib.layouts.klondike.KlondikeLayout

        - row [8 horz S foundation, vert offset]
        - talon [1 NW, no offset]
        - waste [1 E talon, no offset]
        - foundation [8 over 2 rows N, no offset]

      _talon_ : pysollib.stack.Stack
        .. pysollib.stack.WasteTalon

        Deal 1 card per `s.waste` on click. No redeals.

      _waste_ : pysollib.stack.Stack
        .. pysollib.stack.WasteStack

        Init 2 card. Build none. Play top.

      _foundation_ : pysollib.stack.Stack
        .. pysollib.stacks.hanafuda.Rank_Foundation

        Build up in rank by same suit. Play top.

      _row_ : pysollib.stack.Stack
        .. pysollib.stacks.hanafuda.Rank_RowStack

        Init 1..8 card. Build down in rank alone. Play any.

      _hint_ : pysollib.hint.AbstractHint
        .. pysollib.hint.CautiousDefaultHint
    """
    __info__ = dict(id=0x2533e, name='Iris', category=cs.TYPE_HANAFUDA,
                    game_type=GT.KLONDIKE, decks=1, skill_level=SL.BALANCED,
                    version='0.50fc')
    __author__ = 'Mt. Hood Playing Card'
    __version__ = 7.70
    talon_ = stack.WasteTalon


PROVIDES = [DoubleSamuri, Eularia, Iris, Paulownia, Peony, Pine, Samuri,
            SuperSamuri]